//
//  LineLayout.m
//  UI-21-02
//
//  Created by lanou3g on 15/11/30.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "LineLayout.h"
#define kItemX 100
#define kItemY 100
@implementation LineLayout


//准备布局(配置layout基本属性)
-(void)prepareLayout{
    
   
       //上下
    self.minimumLineSpacing = 10;
    //左右
    self.minimumInteritemSpacing = 50;
    //item大小
    self.itemSize = CGSizeMake(ScreenFrame_Widdth, ScreenFrame_Height-120);
    //设置横屏滚动
    self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //
    CGFloat top = (self.collectionView.frame.size.height - kItemY) * 0.5;
    CGFloat left = (self.collectionView.frame.size.width - kItemX) * 0.5;
    self.sectionInset = UIEdgeInsetsMake(top, left, top, left);
}

//是否重新布局(是否时刻改变布局)
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{
    
    
    return YES;
}

//配置item的相关属性
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{
    
    
    
    NSArray *array = [super layoutAttributesForElementsInRect:rect];
    for (UICollectionViewLayoutAttributes *attributes in array) {
        
        //设置偏移量
       CGFloat centerX = self.collectionView.contentOffset.x + self.collectionView.frame.size.width * 0.5;
       CGFloat itemCenterX = attributes.center.x;
        //缩放比例 ABS()取绝对值
        CGFloat scale = 1 + (1 - ABS(centerX - itemCenterX)) / 400;
        //设置天然sform3D
        attributes.transform3D = CATransform3DMakeScale(scale, scale, 1.0);
        
    }
    
    
    return array;
}


@end
